home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / uemacs-3.000 / uemacs-3 / uemacs-3.8 / display.c,v < prev    next >
Encoding:
Text File  |  1995-09-22  |  23.4 KB  |  1,114 lines

  1. head    1.1;
  2. access;
  3. symbols;
  4. locks
  5.     moss:1.1; strict;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.1
  10. date    95.09.22.22.44.43;    author moss;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19. 1.1
  20. log
  21. @Initial revision
  22. @
  23. text
  24. @/*
  25.  * The functions in this file handle redisplay. There are two halves, the
  26.  * ones that update the virtual display screen, and the ones that make the
  27.  * physical display screen the same as the virtual display screen. These
  28.  * functions use hints that are left in the windows by the commands.
  29.  *
  30.  */
  31.  
  32. #include        <stdio.h>
  33. #include    "estruct.h"
  34. #include        "edef.h"
  35.  
  36. #if    MEGAMAX & ST520
  37. overlay    "display"
  38. #endif
  39.  
  40. typedef struct  VIDEO {
  41.         int    v_flag;                 /* Flags */
  42. #if    COLOR
  43.     int    v_fcolor;        /* current forground color */
  44.     int    v_bcolor;        /* current background color */
  45.     int    v_rfcolor;        /* requested forground color */
  46.     int    v_rbcolor;        /* requested background color */
  47. #endif
  48.         char    v_text[1];              /* Screen data. */
  49. }       VIDEO;
  50.  
  51. #define VFCHG   0x0001                  /* Changed flag            */
  52. #define    VFEXT    0x0002            /* extended (beyond column 80)    */
  53. #define    VFREV    0x0004            /* reverse video status        */
  54. #define    VFREQ    0x0008            /* reverse video request    */
  55. #define    VFCOL    0x0010            /* color change requested    */
  56.  
  57. VIDEO   **vscreen;                      /* Virtual screen. */
  58. #if    MEMMAP == 0
  59. VIDEO   **pscreen;                      /* Physical screen. */
  60. #endif
  61.  
  62. /*
  63.  * Initialize the data structures used by the display code. The edge vectors
  64.  * used to access the screens are set up. The operating system's terminal I/O
  65.  * channel is set up. All the other things get initialized at compile time.
  66.  * The original window has "WFCHG" set, so that it will get completely
  67.  * redrawn on the first call to "update".
  68.  */
  69. vtinit()
  70. {
  71.     register int i;
  72.     register VIDEO *vp;
  73.     char *malloc();
  74.  
  75.     TTopen();        /* open the screen */
  76.     TTkopen();        /* open the keyboard */
  77.     TTrev(FALSE);
  78.     vscreen = (VIDEO **) malloc(term.t_nrow*sizeof(VIDEO *));
  79.  
  80.     if (vscreen == NULL)
  81.         exit(1);
  82.  
  83. #if    MEMMAP == 0
  84.     pscreen = (VIDEO **) malloc(term.t_nrow*sizeof(VIDEO *));
  85.  
  86.     if (pscreen == NULL)
  87.         exit(1);
  88. #endif
  89.  
  90.     for (i = 0; i < term.t_nrow; ++i)
  91.         {
  92.         vp = (VIDEO *) malloc(sizeof(VIDEO)+term.t_mcol);
  93.  
  94.         if (vp == NULL)
  95.             exit(1);
  96.  
  97.     vp->v_flag = 0;
  98. #if    COLOR
  99.     vp->v_rfcolor = 7;
  100.     vp->v_rbcolor = 0;
  101. #endif
  102.         vscreen[i] = vp;
  103. #if    MEMMAP == 0
  104.         vp = (VIDEO *) malloc(sizeof(VIDEO)+term.t_mcol);
  105.  
  106.         if (vp == NULL)
  107.             exit(1);
  108.  
  109.     vp->v_flag = 0;
  110.         pscreen[i] = vp;
  111. #endif
  112.         }
  113. }
  114.  
  115. /*
  116.  * Clean up the virtual terminal system, in anticipation for a return to the
  117.  * operating system. Move down to the last line and clear it out (the next
  118.  * system prompt will be written in the line). Shut down the channel to the
  119.  * terminal.
  120.  */
  121. vttidy()
  122. {
  123.     mlerase();
  124.     movecursor(term.t_nrow, 0);
  125.     TTflush();
  126.     TTclose();
  127.     TTkclose();
  128. }
  129.  
  130. /*
  131.  * Set the virtual cursor to the specified row and column on the virtual
  132.  * screen. There is no checking for nonsense values; this might be a good
  133.  * idea during the early stages.
  134.  */
  135. vtmove(row, col)
  136. {
  137.     vtrow = row;
  138.     vtcol = col;
  139. }
  140.  
  141. /* Write a character to the virtual screen. The virtual row and
  142.    column are updated. If we are not yet on left edge, don't print
  143.    it yet. If the line is too long put a "$" in the last column.
  144.    This routine only puts printing characters into the virtual
  145.    terminal buffers. Only column overflow is checked.
  146. */
  147.  
  148. vtputc(c)
  149.  
  150. int c;
  151.  
  152. {
  153.     register VIDEO *vp;    /* ptr to line being updated */
  154.  
  155.     vp = vscreen[vtrow];
  156.  
  157.     if (c == '\t') {
  158.         do {
  159.             vtputc(' ');
  160.         } while (((vtcol + taboff)&0x07) != 0);
  161.     } else if (vtcol >= term.t_ncol) {
  162.         ++vtcol;
  163.         vp->v_text[term.t_ncol - 1] = '$';
  164.     } else if (c < 0x20 || c == 0x7F) {
  165.         vtputc('^');
  166.         vtputc(c ^ 0x40);
  167.     } else {
  168.         if (vtcol >= 0)
  169.             vp->v_text[vtcol] = c;
  170.         ++vtcol;
  171.     }
  172. }
  173.  
  174. /*
  175.  * Erase from the end of the software cursor to the end of the line on which
  176.  * the software cursor is located.
  177.  */
  178. vteeol()
  179. {
  180.     register VIDEO      *vp;
  181.  
  182.     vp = vscreen[vtrow];
  183.     while (vtcol < term.t_ncol)
  184.         vp->v_text[vtcol++] = ' ';
  185. }
  186.  
  187. /* upscreen:    user routine to force a screen update
  188.         always finishes complete update        */
  189.  
  190. upscreen(f, n)
  191.  
  192. {
  193.     update(TRUE);
  194.     return(TRUE);
  195. }
  196.  
  197. /*
  198.  * Make sure that the display is right. This is a three part process. First,
  199.  * scan through all of the windows looking for dirty ones. Check the framing,
  200.  * and refresh the screen. Second, make sure that "currow" and "curcol" are
  201.  * correct for the current window. Third, make the virtual and physical
  202.  * screens the same.
  203.  */
  204. update(force)
  205.  
  206. int force;    /* force update past type ahead? */
  207.  
  208. {
  209.     register WINDOW *wp;
  210.  
  211. #if    TYPEAH
  212.     if (force == FALSE && typahead())
  213.         return(TRUE);
  214. #endif
  215. #if    VISMAC == 0
  216.     if (force == FALSE && kbdmode == PLAY)
  217.         return(TRUE);
  218. #endif
  219.  
  220.     /* update any windows that need refreshing */
  221.     wp = wheadp;
  222.     while (wp != NULL) {
  223.         if (wp->w_flag) {
  224.             /* if the window has changed, service it */
  225.             reframe(wp);    /* check the framing */
  226.             if ((wp->w_flag & ~WFMODE) == WFEDIT)
  227.                 updone(wp);    /* update EDITed line */
  228.             else if (wp->w_flag & ~WFMOVE)
  229.                 updall(wp);    /* update all lines */
  230.             if (wp->w_flag & WFMODE)
  231.                 modeline(wp);    /* update modeline */
  232.             wp->w_flag = 0;
  233.             wp->w_force = 0;
  234.         }
  235.         /* on to the next window */
  236.         wp = wp->w_wndp;
  237.     }
  238.  
  239.     /* recalc the current hardware cursor location */
  240.     updpos();
  241.  
  242. #if    MEMMAP
  243.     /* update the cursor and flush the buffers */
  244.     movecursor(currow, curcol - lbound);
  245. #endif
  246.  
  247.     /* check for lines to de-extend */
  248.     upddex();
  249.  
  250.     /* if screen is garbage, re-plot it */
  251.     if (sgarbf != FALSE)
  252.         updgar();
  253.  
  254.     /* update the virtual screen to the physical screen */
  255.     updupd(force);
  256.  
  257.     /* update the cursor and flush the buffers */
  258.     movecursor(currow, curcol - lbound);
  259.     TTflush();
  260.     return(TRUE);
  261. }
  262.  
  263. /*    reframe:    check to see if the cursor is on in the window
  264.             and re-frame it if needed or wanted        */
  265.  
  266. reframe(wp)
  267.  
  268. WINDOW *wp;
  269.  
  270. {
  271.     register LINE *lp;
  272.     register int i;
  273.  
  274.     /* if not a requested reframe, check for a needed one */
  275.     if ((wp->w_flag & WFFORCE) == 0) {
  276.         lp = wp->w_linep;
  277.         for (i = 0; i < wp->w_ntrows; i++) {
  278.  
  279.             /* if the line is in the window, no reframe */
  280.             if (lp == wp->w_dotp)
  281.                 return(TRUE);
  282.  
  283.             /* if we are at the end of the file, reframe */
  284.             if (lp == wp->w_bufp->b_linep)
  285.                 break;
  286.  
  287.             /* on to the next line */
  288.             lp = lforw(lp);
  289.         }
  290.     }
  291.  
  292.     /* reaching here, we need a window refresh */
  293.     i = wp->w_force;
  294.  
  295.     /* how far back to reframe? */
  296.     if (i > 0) {        /* only one screen worth of lines max */
  297.         if (--i >= wp->w_ntrows)
  298.             i = wp->w_ntrows - 1;
  299.     } else if (i < 0) {    /* negative update???? */
  300.         i += wp->w_ntrows;
  301.         if (i < 0)
  302.             i = 0;
  303.     } else
  304.         i = wp->w_ntrows / 2;
  305.  
  306.     /* backup to new line at top of window */
  307.     lp = wp->w_dotp;
  308.     while (i != 0 && lback(lp) != wp->w_bufp->b_linep) {
  309.         --i;
  310.         lp = lback(lp);
  311.     }
  312.  
  313.     /* and reset the current line at top of window */
  314.     wp->w_linep = lp;
  315.     wp->w_flag |= WFHARD;
  316.     wp->w_flag &= ~WFFORCE;
  317.     return(TRUE);
  318. }
  319.  
  320. /*    updone:    update the current line    to the virtual screen        */
  321.  
  322. updone(wp)
  323.  
  324. WINDOW *wp;    /* window to update current line in */
  325.  
  326. {
  327.     register LINE *lp;    /* line to update */
  328.     register int sline;    /* physical screen line to update */
  329.     register int i;
  330.  
  331.     /* search down the line we want */
  332.     lp = wp->w_linep;
  333.     sline = wp->w_toprow;
  334.     while (lp != wp->w_dotp) {
  335.         ++sline;
  336.         lp = lforw(lp);
  337.     }
  338.  
  339.     /* and update the virtual line */
  340.     vscreen[sline]->v_flag |= VFCHG;
  341.     vscreen[sline]->v_flag &= ~VFREQ;
  342.     vtmove(sline, 0);
  343.     for (i=0; i < llength(lp); ++i)
  344.         vtputc(lgetc(lp, i));
  345. #if    COLOR
  346.     vscreen[sline]->v_rfcolor = wp->w_fcolor;
  347.     vscreen[sline]->v_rbcolor = wp->w_bcolor;
  348. #endif
  349.     vteeol();
  350. }
  351.  
  352. /*    updall:    update all the lines in a window on the virtual screen */
  353.  
  354. updall(wp)
  355.  
  356. WINDOW *wp;    /* window to update lines in */
  357.  
  358. {
  359.     register LINE *lp;    /* line to update */
  360.     register int sline;    /* physical screen line to update */
  361.     register int i;
  362.  
  363.     /* search down the lines, updating them */
  364.     lp = wp->w_linep;
  365.     sline = wp->w_toprow;
  366.     while (sline < wp->w_toprow + wp->w_ntrows) {
  367.  
  368.         /* and update the virtual line */
  369.         vscreen[sline]->v_flag |= VFCHG;
  370.         vscreen[sline]->v_flag &= ~VFREQ;
  371.         vtmove(sline, 0);
  372.         if (lp != wp->w_bufp->b_linep) {
  373.             /* if we are not at the end */
  374.             for (i=0; i < llength(lp); ++i)
  375.                 vtputc(lgetc(lp, i));
  376.             lp = lforw(lp);
  377.         }
  378.  
  379.         /* on to the next one */
  380. #if    COLOR
  381.         vscreen[sline]->v_rfcolor = wp->w_fcolor;
  382.         vscreen[sline]->v_rbcolor = wp->w_bcolor;
  383. #endif
  384.         vteeol();
  385.         ++sline;
  386.     }
  387.  
  388. }
  389.  
  390. /*    updpos:    update the position of the hardware cursor and handle extended
  391.         lines. This is the only update for simple moves.    */
  392.  
  393. updpos()
  394.  
  395. {
  396.     register LINE *lp;
  397.     register int c;
  398.     register int i;
  399.  
  400.     /* find the current row */
  401.     lp = curwp->w_linep;
  402.     currow = curwp->w_toprow;
  403.     while (lp != curwp->w_dotp) {
  404.         ++currow;
  405.         lp = lforw(lp);
  406.     }
  407.  
  408.     /* find the current column */
  409.     curcol = 0;
  410.     i = 0;
  411.     while (i < curwp->w_doto) {
  412.         c = lgetc(lp, i++);
  413.         if (c == '\t')
  414.             curcol |= 0x07;
  415.         else
  416.             if (c < 0x20 || c == 0x7f)
  417.                 ++curcol;
  418.  
  419.         ++curcol;
  420.     }
  421.  
  422.     /* if extended, flag so and update the virtual line image */
  423.     if (curcol >=  term.t_ncol - 1) {
  424.         vscreen[currow]->v_flag |= (VFEXT | VFCHG);
  425.         updext();
  426.     } else
  427.         lbound = 0;
  428. }
  429.  
  430. /*    upddex:    de-extend any line that derserves it        */
  431.  
  432. upddex()
  433.  
  434. {
  435.     register WINDOW *wp;
  436.     register LINE *lp;
  437.     register int i,j;
  438.  
  439.     wp = wheadp;
  440.  
  441.     while (wp != NULL) {
  442.         lp = wp->w_linep;
  443.         i = wp->w_toprow;
  444.  
  445.         while (i < wp->w_toprow + wp->w_ntrows) {
  446.             if (vscreen[i]->v_flag & VFEXT) {
  447.                 if ((wp != curwp) || (lp != wp->w_dotp) ||
  448.                    (curcol < term.t_ncol - 1)) {
  449.                     vtmove(i, 0);
  450.                     for (j = 0; j < llength(lp); ++j)
  451.                         vtputc(lgetc(lp, j));
  452.                     vteeol();
  453.  
  454.                     /* this line no longer is extended */
  455.                     vscreen[i]->v_flag &= ~VFEXT;
  456.                     vscreen[i]->v_flag |= VFCHG;
  457.                 }
  458.             }
  459.             lp = lforw(lp);
  460.             ++i;
  461.         }
  462.         /* and onward to the next window */
  463.         wp = wp->w_wndp;
  464.     }
  465. }
  466.  
  467. /*    updgar:    if the screen is garbage, clear the physical screen and
  468.         the virtual screen and force a full update        */
  469.  
  470. updgar()
  471.  
  472. {
  473.     register char *txt;
  474.     register int i,j;
  475.  
  476.     for (i = 0; i < term.t_nrow; ++i) {
  477.         vscreen[i]->v_flag |= VFCHG;
  478. #if    REVSTA
  479.         vscreen[i]->v_flag &= ~VFREV;
  480. #endif
  481. #if    COLOR
  482.         vscreen[i]->v_fcolor = gfcolor;
  483.         vscreen[i]->v_bcolor = gbcolor;
  484. #endif
  485. #if    MEMMAP == 0
  486.         txt = pscreen[i]->v_text;
  487.         for (j = 0; j < term.t_ncol; ++j)
  488.             txt[j] = ' ';
  489. #endif
  490.     }
  491.  
  492.     movecursor(0, 0);         /* Erase the screen. */
  493.     (*term.t_eeop)();
  494.     sgarbf = FALSE;             /* Erase-page clears */
  495.     mpresf = FALSE;             /* the message area. */
  496. #if    COLOR
  497.     mlerase();            /* needs to be cleared if colored */
  498. #endif
  499. }
  500.  
  501. /*    updupd:    update the physical screen from the virtual screen    */
  502.  
  503. updupd(force)
  504.  
  505. int force;    /* forced update flag */
  506.  
  507. {
  508.     register VIDEO *vp1;
  509.     register int i;
  510.  
  511.     for (i = 0; i < term.t_nrow; ++i) {
  512.         vp1 = vscreen[i];
  513.  
  514.         /* for each line that needs to be updated*/
  515.         if ((vp1->v_flag & VFCHG) != 0) {
  516. #if    TYPEAH
  517.             if (force == FALSE && typahead())
  518.                 return(TRUE);
  519. #endif
  520. #if    MEMMAP
  521.             updateline(i, vp1);
  522. #else
  523.             updateline(i, vp1, pscreen[i]);
  524. #endif
  525.         }
  526.     }
  527.     return(TRUE);
  528. }
  529.  
  530. /*    updext: update the extended line which the cursor is currently
  531.         on at a column greater than the terminal width. The line
  532.         will be scrolled right or left to let the user see where
  533.         the cursor is
  534.                                 */
  535.  
  536. updext()
  537.  
  538. {
  539.     register int rcursor;    /* real cursor location */
  540.     register LINE *lp;    /* pointer to current line */
  541.     register int j;        /* index into line */
  542.  
  543.     /* calculate what column the real cursor will end up in */
  544.     rcursor = ((curcol - term.t_ncol) % term.t_scrsiz) + term.t_margin;
  545.     taboff = lbound = curcol - rcursor + 1;
  546.  
  547.     /* scan through the line outputing characters to the virtual screen */
  548.     /* once we reach the left edge                    */
  549.     vtmove(currow, -lbound);    /* start scanning offscreen */
  550.     lp = curwp->w_dotp;        /* line to output */
  551.     for (j=0; j<llength(lp); ++j)    /* until the end-of-line */
  552.         vtputc(lgetc(lp, j));
  553.  
  554.     /* truncate the virtual line, restore tab offset */
  555.     vteeol();
  556.     taboff = 0;
  557.  
  558.     /* and put a '$' in column 1 */
  559.     vscreen[currow]->v_text[0] = '$';
  560. }
  561.  
  562. /*
  563.  * Update a single line. This does not know how to use insert or delete
  564.  * character sequences; we are using VT52 functionality. Update the physical
  565.  * row and column variables. It does try an exploit erase to end of line. The
  566.  * RAINBOW version of this routine uses fast video.
  567.  */
  568. #if    MEMMAP
  569. /*    UPDATELINE specific code for the IBM-PC and other compatables */
  570.  
  571. updateline(row, vp1)
  572.  
  573. int row;        /* row of screen to update */
  574. struct VIDEO *vp1;    /* virtual screen image */
  575.  
  576. {
  577. #if    COLOR
  578.     scwrite(row, vp1->v_text, vp1->v_rfcolor, vp1->v_rbcolor);
  579.     vp1->v_fcolor = vp1->v_rfcolor;
  580.     vp1->v_bcolor = vp1->v_rbcolor;
  581. #else
  582.     if (vp1->v_flag & VFREQ)
  583.         scwrite(row, vp1->v_text, 0, 7);
  584.     else
  585.         scwrite(row, vp1->v_text, 7, 0);
  586. #endif
  587.     vp1->v_flag &= ~(VFCHG | VFCOL);    /* flag this line as changed */
  588.  
  589. }
  590.  
  591. #else
  592.  
  593. updateline(row, vp1, vp2)
  594.  
  595. int row;        /* row of screen to update */
  596. struct VIDEO *vp1;    /* virtual screen image */
  597. struct VIDEO *vp2;    /* physical screen image */
  598.  
  599. {
  600. #if RAINBOW
  601. /*    UPDATELINE specific code for the DEC rainbow 100 micro    */
  602.  
  603.     register char *cp1;
  604.     register char *cp2;
  605.     register int nch;
  606.  
  607.     /* since we don't know how to make the rainbow do this, turn it off */
  608.     flags &= (~VFREV & ~VFREQ);
  609.  
  610.     cp1 = &vp1->v_text[0];                    /* Use fast video. */
  611.     cp2 = &vp2->v_text[0];
  612.     putline(row+1, 1, cp1);
  613.     nch = term.t_ncol;
  614.  
  615.     do
  616.         {
  617.         *cp2 = *cp1;
  618.         ++cp2;
  619.         ++cp1;
  620.         }
  621.     while (--nch);
  622.     *flags &= ~VFCHG;
  623. #else
  624. /*    UPDATELINE code for all other versions        */
  625.  
  626.     register char *cp1;
  627.     register char *cp2;
  628.     register char *cp3;
  629.     register char *cp4;
  630.     register char *cp5;
  631.     register int nbflag;    /* non-blanks to the right flag? */
  632.     int rev;        /* reverse video flag */
  633.     int req;        /* reverse video request flag */
  634.  
  635.  
  636.     /* set up pointers to virtual and physical lines */
  637.     cp1 = &vp1->v_text[0];
  638.     cp2 = &vp2->v_text[0];
  639.  
  640. #if    COLOR
  641.     TTforg(vp1->v_rfcolor);
  642.     TTbacg(vp1->v_rbcolor);
  643. #endif
  644.  
  645. #if    REVSTA | COLOR
  646.     /* if we need to change the reverse video status of the
  647.        current line, we need to re-write the entire line     */
  648.     rev = (vp1->v_flag & VFREV) == VFREV;
  649.     req = (vp1->v_flag & VFREQ) == VFREQ;
  650.     if ((rev != req)
  651. #if    COLOR
  652.         || (vp1->v_fcolor != vp1->v_rfcolor) || (vp1->v_bcolor != vp1->v_rbcolor)
  653. #endif
  654. #if    HP150
  655.     /* the HP150 has some reverse video problems */
  656.         || req || rev
  657. #endif
  658.             ) {
  659.         movecursor(row, 0);    /* Go to start of line. */
  660.         /* set rev video if needed */
  661.         if (rev != req)
  662.             (*term.t_rev)(req);
  663.  
  664.         /* scan through the line and dump it to the screen and
  665.            the virtual screen array                */
  666.         cp3 = &vp1->v_text[term.t_ncol];
  667.         while (cp1 < cp3) {
  668.             TTputc(*cp1);
  669.             ++ttcol;
  670.             *cp2++ = *cp1++;
  671.         }
  672.         /* turn rev video off */
  673.         if (rev != req)
  674.             (*term.t_rev)(FALSE);
  675.  
  676.         /* update the needed flags */
  677.         vp1->v_flag &= ~VFCHG;
  678.         if (req)
  679.             vp1->v_flag |= VFREV;
  680.         else
  681.             vp1->v_flag &= ~VFREV;
  682. #if    COLOR
  683.         vp1->v_fcolor = vp1->v_rfcolor;
  684.         vp1->v_bcolor = vp1->v_rbcolor;
  685. #endif
  686.         return(TRUE);
  687.     }
  688. #endif
  689.  
  690.     /* advance past any common chars at the left */
  691.     while (cp1 != &vp1->v_text[term.t_ncol] && cp1[0] == cp2[0]) {
  692.         ++cp1;
  693.         ++cp2;
  694.     }
  695.  
  696. /* This can still happen, even though we only call this routine on changed
  697.  * lines. A hard update is always done when a line splits, a massive
  698.  * change is done, or a buffer is displayed twice. This optimizes out most
  699.  * of the excess updating. A lot of computes are used, but these tend to
  700.  * be hard operations that do a lot of update, so I don't really care.
  701.  */
  702.     /* if both lines are the same, no update needs to be done */
  703.     if (cp1 == &vp1->v_text[term.t_ncol]) {
  704.          vp1->v_flag &= ~VFCHG;        /* flag this line is changed */
  705.         return(TRUE);
  706.     }
  707.  
  708.     /* find out if there is a match on the right */
  709.     nbflag = FALSE;
  710.     cp3 = &vp1->v_text[term.t_ncol];
  711.     cp4 = &vp2->v_text[term.t_ncol];
  712.  
  713.     while (cp3[-1] == cp4[-1]) {
  714.         --cp3;
  715.         --cp4;
  716.         if (cp3[0] != ' ')        /* Note if any nonblank */
  717.             nbflag = TRUE;        /* in right match. */
  718.     }
  719.  
  720.     cp5 = cp3;
  721.  
  722.     /* Erase to EOL ? */
  723.     if (nbflag == FALSE && eolexist == TRUE && (req != TRUE)) {
  724.         while (cp5!=cp1 && cp5[-1]==' ')
  725.             --cp5;
  726.  
  727.         if (cp3-cp5 <= 3)        /* Use only if erase is */
  728.             cp5 = cp3;        /* fewer characters. */
  729.     }
  730.  
  731.     movecursor(row, cp1 - &vp1->v_text[0]);    /* Go to start of line. */
  732. #if    REVSTA
  733.     TTrev(rev);
  734. #endif
  735.  
  736.     while (cp1 != cp5) {        /* Ordinary. */
  737.         TTputc(*cp1);
  738.         ++ttcol;
  739.         *cp2++ = *cp1++;
  740.     }
  741.  
  742.     if (cp5 != cp3) {        /* Erase. */
  743.         TTeeol();
  744.         while (cp1 != cp3)
  745.             *cp2++ = *cp1++;
  746.     }
  747. #if    REVSTA
  748.     TTrev(FALSE);
  749. #endif
  750.     vp1->v_flag &= ~VFCHG;        /* flag this line as updated */
  751.     return(TRUE);
  752. #endif
  753. }
  754. #endif
  755.  
  756. /*
  757.  * Redisplay the mode line for the window pointed to by the "wp". This is the
  758.  * only routine that has any idea of how the modeline is formatted. You can
  759.  * change the modeline format by hacking at this routine. Called by "update"
  760.  * any time there is a dirty window.
  761.  */
  762. modeline(wp)
  763.     WINDOW *wp;
  764. {
  765.     register char *cp;
  766.     register int c;
  767.     register int n;        /* cursor position count */
  768.     register BUFFER *bp;
  769.     register i;            /* loop index */
  770.     register lchar;        /* character to draw line in buffer with */
  771.     register firstm;        /* is this the first mode? */
  772.     char tline[NLINE];        /* buffer for part of mode line */
  773.  
  774.     n = wp->w_toprow+wp->w_ntrows;          /* Location. */
  775.     vscreen[n]->v_flag |= VFCHG | VFREQ | VFCOL;/* Redraw next time. */
  776. #if    COLOR
  777.     vscreen[n]->v_rfcolor = 0;            /* black on */
  778.     vscreen[n]->v_rbcolor = 7;            /* white.....*/
  779. #endif
  780.     vtmove(n, 0);                           /* Seek to right line. */
  781.     if (wp == curwp)                /* mark the current buffer */
  782.     lchar = '=';
  783.     else
  784. #if    REVSTA
  785.     if (revexist)
  786.         lchar = ' ';
  787.     else
  788. #endif
  789.         lchar = '-';
  790.  
  791.     vtputc(lchar);
  792.     bp = wp->w_bufp;
  793.  
  794.     if ((bp->b_flag&BFCHG) != 0)                /* "*" if changed. */
  795.         vtputc('*');
  796.     else
  797.         vtputc(lchaX
  798.     n  = 2;
  799.     strcpy(tline, " MicroEMACS ");        /* Buffer name. */
  800.     strcat(tline, VERSION);
  801.     strcat(tline, " (");
  802.  
  803.     /* display the modes */
  804.  
  805.     firstm = TRUE;
  806.     for (i = 0; i < NUMMODES; i++)    /* add in the mode flags */
  807.         if (wp->w_bufp->b_mode & (1 << i)) {
  808.             if (firstm != TRUE)
  809.                 strcat(tline, " ");
  810.             firstm = FALSE;
  811.             strcat(tline, modename[i]);
  812.         }
  813.     strcat(tline,") ");
  814.  
  815.     cp = &tline[0];
  816.     while ((c = *cp++) != 0)
  817.         {
  818.         vtputc(c);
  819.         ++n;
  820.         }
  821.  
  822. #if 0
  823.     vtputc(lchar);
  824.     vtputc((wp->w_flag&WFCOLR) != 0  ? 'C' : lchar);
  825.     vtputc((wp->w_flag&WFMODE) != 0  ? 'M' : lchar);
  826.     vtputc((wp->w_flag&WFHARD) != 0  ? 'H' : lchar);
  827.     vtputc((wp->w_flag&WFEDIT) != 0  ? 'E' : lchar);
  828.     vtputc((wp->w_flag&WFMOVE) != 0  ? 'V' : lchar);
  829.     vtputc((wp->w_flag&WFFORCE) != 0 ? 'F' : lchar);
  830.     vtputc(lchar);
  831.     n += 8;
  832. #endif
  833.  
  834.     vtputc(lchar);
  835.     vtputc(lchar);
  836.     vtputc(' ');
  837.     n += 3;
  838.     cp = &bp->b_bname[0];
  839.  
  840.     while ((c = *cp++) != 0)
  841.         {
  842.         vtputc(c);
  843.         ++n;
  844.         }
  845.  
  846.     vtputc(' ');
  847.     vtputc(lchar);
  848.     vtputc(lchar);
  849.     n += 3;
  850.  
  851.     if (bp->b_fname[0] != 0)            /* File name. */
  852.         {
  853.     vtputc(' ');
  854.     ++n;
  855.         cp = "File: ";
  856.  
  857.         while ((c = *cp++) != 0)
  858.             {
  859.             vtputc(c);
  860.             ++n;
  861.             }
  862.  
  863.         cp = &bp->b_fname[0];
  864.  
  865.         while ((c = *cp++) != 0)
  866.             {
  867.             vtputc(c);
  868.             ++n;
  869.             }
  870.  
  871.         vtputc(' ');
  872.         ++n;
  873.         }
  874.  
  875.     while (n < term.t_ncol)             /* Pad to full width. */
  876.         {
  877.         vtputc(lchar);
  878.         ++n;
  879.         }
  880. }
  881.  
  882. upmode()    /* update all the mode lines */
  883.  
  884. {
  885.     register WINDOW *wp;
  886.  
  887.     wp = wheadp;
  888.     while (wp != NULL) {
  889.         wp->w_flag |= WFMODE;
  890.         wp = wp->w_wndp;
  891.     }
  892. }
  893.  
  894. /*
  895.  * Send a command to the terminal to move the hardware cursor to row "row"
  896.  * and column "col". The row and column arguments are origin 0. Optimize out
  897.  * random calls. Update "ttrow" and "ttcol".
  898.  */
  899. movecursor(row, col)
  900.     {
  901.     if (row!=ttrow || col!=ttcol)
  902.         {
  903.         ttrow = row;
  904.         ttcol = col;
  905.         TTmove(row, col);
  906.         }
  907.     }
  908.  
  909. /*
  910.  * Erase the message line. This is a special routine because the message line
  911.  * is not considered to be part of the virtual screen. It always works
  912.  * immediately; the terminal buffer is flushed via a call to the flusher.
  913.  */
  914. mlerase()
  915.     {
  916.     int i;
  917.     
  918.     movecursor(term.t_nrow, 0);
  919. #if    COLOR
  920.      TTforg(7);
  921.      TTbacg(0);
  922. #endif
  923.     if (eolexist == TRUE)
  924.         TTeeol();
  925.     else {
  926.         for (i = 0; i < term.t_ncol - 1; i++)
  927.             TTputc(' ');
  928.         movecursor(term.t_nrow, 1);    /* force the move! */
  929.         movecursor(term.t_nrow, 0);
  930.     }
  931.     TTflush();
  932.     mpresf = FALSE;
  933.     }
  934.  
  935. /*
  936.  * Write a message into the message line. Keep track of the physical cursor
  937.  * position. A small class of printf like format items is handled. Assumes the
  938.  * stack grows down; this assumption is made by the "++" in the argument scan
  939.  * loop. Set the "message line" flag TRUE.
  940.  */
  941.  
  942. mlwrite(fmt, arg)
  943.     char *fmt;
  944.     {
  945.     register int c;
  946.     register char *ap;
  947.  
  948. #if    COLOR
  949.     TTforg(7);
  950.     TTbacg(0);
  951. #endif
  952.     if (eolexist == FALSE) {
  953.         mlerase();
  954.         TTflush();
  955.     }
  956.  
  957.     movecursor(term.t_nrow, 0);
  958.     ap = (char *) &arg;
  959.     while ((c = *fmt++) != 0) {
  960.         if (c != '%') {
  961.             TTputc(c);
  962.             ++ttcol;
  963.             }
  964.         else
  965.             {
  966.             c = *fmt++;
  967.             switch (c) {
  968.                 case 'd':
  969.                     mlputi(*(int *)ap, 10);
  970.                     ap += sizeof(int);
  971.                     break;
  972.  
  973.                 case 'o':
  974.                     mlputi(*(int *)ap,  8);
  975.                     ap += sizeof(int);
  976.                     break;
  977.  
  978.                 case 'x':
  979.                     mlputi(*(int *)ap, 16);
  980.                     ap += sizeof(int);
  981.                     break;
  982.  
  983.                 case 'D':
  984.                     mlputli(*(long *)ap, 10);
  985.                     ap += sizeof(long);
  986.                     break;
  987.  
  988.                 case 's':
  989.                     mlputs(*(char **)ap);
  990.                     ap += sizeof(char *);
  991.                     break;
  992.  
  993.         case 'f':
  994.             mlputf(*(int *)ap);
  995.             ap += sizeof(int);
  996.             break;
  997.  
  998.                 default:
  999.                     TTputc(c);
  1000.                     ++ttcol;
  1001.                 }
  1002.             }
  1003.         }
  1004.     if (eolexist == TRUE)
  1005.         TTeeol();
  1006.     TTflush();
  1007.     mpresf = TRUE;
  1008.     }
  1009.  
  1010. /*
  1011.  * Write out a string. Update the physical cursor position. This assumes that
  1012.  * the characters in the string all have width "1"; if this is not the case
  1013.  * things will get screwed up a little.
  1014.  */
  1015. mlputs(s)
  1016.     char *s;
  1017.     {
  1018.     register int c;
  1019.  
  1020.     while ((c = *s++) != 0)
  1021.         {
  1022.         TTputc(c);
  1023.         ++ttcol;
  1024.         }
  1025.     }
  1026.  
  1027. /*
  1028.  * Write out an integer, in the specified radix. Update the physical cursor
  1029.  * position.
  1030.  */
  1031. mlputi(i, r)
  1032.     {
  1033.     register int q;
  1034.     static char hexdigits[] = "0123456789ABCDEF";
  1035.  
  1036.     if (i < 0)
  1037.         {
  1038.         i = -i;
  1039.         TTputc('-');
  1040.         }
  1041.  
  1042.     q = i/r;
  1043.  
  1044.     if (q != 0)
  1045.         mlputi(q, r);
  1046.  
  1047.     TTputc(hexdigits[i%r]);
  1048.     ++ttcol;
  1049.     }
  1050.  
  1051. /*
  1052.  * do the same except as a long integer.
  1053.  */
  1054. mlputli(l, r)
  1055.     long l;
  1056.     {
  1057.     register long q;
  1058.  
  1059.     if (l < 0)
  1060.         {
  1061.         l = -l;
  1062.         TTputc('-');
  1063.         }
  1064.  
  1065.     q = l/r;
  1066.  
  1067.     if (q != 0)
  1068.         mlputli(q, r);
  1069.  
  1070.     TTputc((int)(l%r)+'0');
  1071.     ++ttcol;
  1072.     }
  1073.  
  1074. /*
  1075.  *    write out a scaled integer with two decimal places
  1076.  */
  1077.  
  1078. mlputf(s)
  1079.  
  1080. int s;    /* scaled integer to output */
  1081.  
  1082. {
  1083.     int i;    /* integer portion of number */
  1084.     int f;    /* fractional portion of number */
  1085.  
  1086.     /* break it up */
  1087.     i = s / 100;
  1088.     f = s % 100;
  1089.  
  1090.     /* send out the integer portion */
  1091.     mlputi(i, 10);
  1092.     TTputc('.');
  1093.     TTputc((f / 10) + '0');
  1094.     TTputc((f % 10) + '0');
  1095.     ttcol += 3;
  1096. }    
  1097.  
  1098. #if RAINBOW
  1099.  
  1100. putline(row, col, buf)
  1101.     int row, col;
  1102.     char buf[];
  1103.     {
  1104.     int n;
  1105.  
  1106.     n = strlen(buf);
  1107.     if (col + n - 1 > term.t_ncol)
  1108.         n = term.t_ncol - col + 1;
  1109.     Put_Data(row, col, n, buf);
  1110.     }
  1111. #endif
  1112.  
  1113. @
  1114.